import { ecs } from "db://app-game/libs/ecs/ECS";
import { Role } from "../Role";
import { RoleModelComp } from "../model/RoleModelComp";
import { RoleModelEquipmentComp } from "../model/RoleModelEquipmentComp";

/**
 * 角色切换武器组件
 */
@ecs.register("RoleChangeWeapon")
export class RoleChangeWeaponComp extends ecs.Comp {
  /** 武器Id */
  weaponId: number = -1;

  reset() {
    this.weaponId = -1;
  }
}

/**
 * 角色切换武器系统
 */
@ecs.register("RoleChangeWeapon")
export class RoleChangeWeaponSystem
  extends ecs.ComblockSystem
  implements ecs.IEntityEnterSystem
{
  filter(): ecs.IMatcher {
    return ecs.allOf(
      RoleChangeWeaponComp,
      RoleModelEquipmentComp,
      RoleModelComp
    );
  }

  entityEnter(role: Role): void {
    // 武器更新逻辑
    role.RoleModelEquipment.weapon = role.RoleChangeWeapon.weaponId;

    //

    role.remove(RoleChangeWeaponComp);
  }
}
